package com.qf.utils;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.io.InputStream;
import java.util.Properties;

/**
 * 2020/12/9 9:57
 *
 * @author：Lixubiao
 */
public class DataSourceUtils {
    private static  DruidDataSource dataSource=null;
    static {
        try {
            InputStream rs = DataSourceUtils.class.getClassLoader().getResourceAsStream("db.properties");
            System.out.println(rs);
            Properties properties = new Properties();
            properties.load(rs);
            System.out.println(properties.getProperty("url"));
            dataSource= (DruidDataSource) DruidDataSourceFactory.createDataSource(properties);
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e.getMessage()+"加载连接池失败！");
        }
    }
    public static DataSource getDataSource(){
        return dataSource;
    }

}
